<template>
	<view>
		<view class="cardbox" style="padding-top: 10px; background-color: white;">
			
			<view class="newcard" style="display: flex;flex-direction: column;">
				<view style="flex-direction: row;display:flex">
					<view v-if="mode===2">
						<image class="New_image" :src="showImage" @error="handlerImageError()"></image>
					</view>
					<text v-if="mode===3" style=" color: #636363;font-size: 16px; margin: 0 auto;">{{jds}}</text>
					<text class="xinwen_text" style="margin: 5px;color: ;" v-else>{{jds}}</text>
				</view>
				<view class="adbox" v-if="mode===3" style="background-color: aqua;" >
					<view v-for="(item,index) in images">
						<image :src="item" mode="aspectFill" @error="handlerImageError(index)"></image>
					</view>		  
				</view>
				<view style="display: flex;justify-content: space-between;margin: 10rpx;">
					<view style="display: flex" >
						<text style="color: red;" class="neirong" v-if="isTop">置顶</text>
						<text style="color: blue;" class="neirong" v-if="mode==3">广告</text>
						<text class="neirong" v-if="mode==3"  >{{author}}</text>
						<text class="neirong" v-else>{{author}}</text>
						<text class="neirong" v-if="mode!=3" >{{comments}}评</text>
					</view>
					<text class="neirong" >{{time}}</text>
				</view>
				<slot name="taidu"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "cardViewText",
		data() {
			return {
				defaultImage: "/static/city3.jpg",
				failImage: "/static/photofail.png",
				imageError: false
			};
		},
		computed: {
			showImage() {
				if (this.image) {
					if (this.imageError) {
						console.log("showImage failImage" + this.nid + this.jds);
						return this.failImage;
					}
					return this.image;
				} else {
					console.log("showImage defaultImage" + this.nid + this.jds);
					return this.defaultImage;
				}
			}
		},
		methods: {
			handlerImageError() {
				console.log("handlerImageError:" + this.jds);
				this.imageError = true;
			}
		},
		props: {
			nid: {
				type: String,
				default: "00000"
			},
			isTop: {
				type: Boolean,
				default: false,
				required: true
			},
			jds: {
				type: String,
				default: "新闻标题",
				required: true
			},
			comments: {
				type: String,
				default: "数量",
				required: true
			},
			author: {
				type: String,
				default: "作者",
				required: true
			},
			time: {
				type: String,
				default: "2025.1.1"
			},
			mode: {
				type: Number,
				default: 1
			},
			image: {
				type: String,
				default: ""
			},
		}
	}
</script>

<style>
	.cardbox {
		display: flex;
		flex-direction: column;
		border-radius: 10rpx;
		justify-content: center;
		width: 95%;
		margin: 10px auto;
	}
	.tianqi{
		display: flex;
		flex-direction: column;
		justify-content: center;
		width:100% ;
	}
	.newcard {
		display: flex;
		flex-direction: column;
		border-radius: 10rpx;
		justify-content: center;
		margin: 0 0 5px 5px;
	}

	.xinwen_text {
		font-size: 32rpx;
		word-wrap: break-word;
	}

	.neirong {
		margin-right: 5px;
		color: #636363;
		font-size: 14px;
	}

	.New_image {
		height: 100px;
		width: 100px;
		margin: 5px;
		object-fit: cover;
	}
	.adbox{
		display: flex;
		flex-direction: row;
		border-radius: 10rpx;
		justify-content: space-around;
		width: 95%;
		margin: 10px auto; 
		
	}
</style>